<style lang="less">
// @import "./supplierManage.less";
</style>
<template>
  <Modal :title="modalTitle" v-model="isShow" :mask-closable='false' :width="500" @on-cancel="cancelReview">
    <Form ref="reviewForm" :model="reviewForm" :label-width="100" :rules="reviewFormValidate">
        <FormItem label="审核状态" prop="reviewStatus">
            <RadioGroup v-model="reviewForm.reviewStatus" @on-change="revewStatusChange">
              <Radio label="0">未审核</Radio>
              <Radio label="-1">未通过</Radio>
              <Radio label="1">通过</Radio>
          </RadioGroup>
        </FormItem>
        <FormItem label="原因描述" prop="nopassReason" v-if="reviewForm.nopassReasonVisible">
            <textarea v-model="reviewForm.nopassReason" style="width:340px;height:60px;resize:none;line-height:2.0;border:1px solid #dddee1;"/>
        </FormItem>          
    </Form>
    <div slot="footer">
        <Button type="text" @click="cancelReview">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="submitReview">提交</Button>
    </div>
  </Modal>
</template>

<script>

export default {
  name: "review-modal-comp",
  props:{
    // isShow: {
    //   type: Boolean,
    //   default: false
    // },
    // reviewObject: {
    //   type: Object,
    //   default: false
    // }
    // reviewModalTitle: {
    //   type: String,
    //   default: ""
    // },
    // reviewStatus: {
    //   type: String,
    //   default: ""
    // },
  },
  data() {
    return {
      isShow: false,
      reviewUrl: "",
      modalTitle: "",
      reviewForm: {
        reviewId:"",
        reviewStatus: "",
        nopassReason: "",
        nopassReasonVisible: false
      },
      submitLoading: false,
      reviewFormValidate: {
      }
    };
  },
  methods: {
    openReviewModal(isOpen,reviewUrl,reviewObj){
      this.reviewUrl = reviewUrl;
      let reviewObject = reviewObj;
      if(reviewObject){
        this.modalTitle = reviewObject.title;
        this.reviewForm.reviewId = reviewObject.reviewId;
        let status = reviewObject.status;
        this.reviewForm.reviewStatus = status;
        (status === "-1") ? (this.reviewForm.nopassReasonVisible = true) : (this.reviewForm.nopassReasonVisible = false);
        this.reviewForm.nopassReason = reviewObject.reason;
      }
      this.isShow  = isOpen;
    },
    revewStatusChange(value) {
      (value === "-1") ? (this.reviewForm.nopassReasonVisible = true) : (this.reviewForm.nopassReasonVisible = false);
    },
    cancelReview() {
      this.isShow =  false;
      this.reviewForm.nopassReason="";
      this.$emit('on-close',true);
    },
    submitReview(){
      // let url = "";
      // url = "/goods_item/review";
      let reviewObj = {};
      reviewObj.id = this.reviewForm.reviewId;
      let status = this.reviewForm.reviewStatus;
      reviewObj.status = status;
      (status === "-1") ? (reviewObj.reason = this.reviewForm.nopassReason) : (reviewObj.reason = '');
      console.log(reviewObj);
      this.submitLoading = true;
      this.putRequest(this.reviewUrl, reviewObj).then(res => {
        this.submitLoading = false;
        if (res.success === true) {
          this.$Message.success("审核操作成功");
          this.isShow = false;
          this.$emit('on-review-success',true);
        }
      });
    }

  },
  mounted() {
  }
};
</script>